package resolver

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.

import (
	"context"
	"errors"
	"fmt"

	"mall/service/setting/rpc/setting"
	"mall/service/wpgql/api/internal/graph/helper"
	"mall/service/wpgql/api/internal/graph/model"
)

const generalSettingsError = "could not list blog general settings"

func (r *mutationResolver) UpdateSettings(ctx context.Context, input model.UpdateSettingsInput) (*model.UpdateSettingsPayload, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *queryResolver) AllSettings(ctx context.Context) (*model.Settings, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *queryResolver) DiscussionSettings(ctx context.Context) (*model.DiscussionSettings, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *queryResolver) GeneralSettings(ctx context.Context) (*model.GeneralSettings, error) {
	req := &setting.SettingListRequest{}

	preload, eagerLoad := helper.GetBlogGeneralSettingPreloads(ctx)
	if preload != "" {
		req.Preload = preload
	}
	if eagerLoad != "" {
		req.EagerLoad = eagerLoad
	}

	resp := &model.GeneralSettings{}

	res, err := r.svcCtx.SettingRpc.SettingList(ctx, req)
	if err != nil {
		return resp, errors.New(generalSettingsError)
	}

	if len(res.Data) > 0 {
		resp = helper.BlogGeneralSettingsToGraphQL(res.Data)
	}

	return resp, nil
}

func (r *queryResolver) ReadingSettings(ctx context.Context) (*model.ReadingSettings, error) {
	panic(fmt.Errorf("not implemented"))
}

func (r *queryResolver) WritingSettings(ctx context.Context) (*model.WritingSettings, error) {
	panic(fmt.Errorf("not implemented"))
}
